package com.heima.controller;

import com.heima.pojo.business.BusinessType;
import com.heima.pojo.node.*;
import com.heima.service.NodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "点位管理相关接口")
@RequestMapping("/api/vm-service")
@RequiredArgsConstructor
@Slf4j
public class NodeController {
    private final NodeService nodeService;

    /**
     * 点位搜索
     * @param param
     * @return
     */
    @ApiOperation("点位搜索")
    @GetMapping("/node/search")
    public NodePageResult search(NodeQueryParam param){
        log.info("点位搜索：{}",param);
        NodePageResult result = nodeService.search(param);
        return result;
    }
    /**
     * 新增点位接口1
     */
    @ApiOperation("新增点位接口1")
    @GetMapping("/businessType")
    public List<BusinessType> getBusinessType(){
        log.info("查询商圈列表");
        List<BusinessType> result=nodeService.getBusinessType();
        return result;
    }
    /**
     * 新增点位接口2
     */
    @ApiOperation("新增点位接口2")
    @PostMapping("/node")
    public void addNode(@RequestBody Node node){
        log.info("新增点位：{}",node);
        nodeService.addNode(node);
    }
    /**
     * 点位详情
     */
    @ApiOperation("点位详情")
    @GetMapping("/node/vmList/{id}")
    public List<VendingMachine> getVmList(@PathVariable String id){
        log.info("查询点位下的设备列表：{}",id);
        List<VendingMachine> result=nodeService.getVmList(id);
        return result;
    }
    /**
     * 修改点位
     */
    @ApiOperation("修改点位")
    @PutMapping("/node/{nodeId}")
    public void updateNode(@PathVariable String nodeId,@RequestBody Node node){
        log.info("修改点位：{}",node);
        node.setId(nodeId);
        nodeService.updateNode(node);
    }
    /**
     * 删除点位
     */
    @ApiOperation("删除点位")
    @DeleteMapping("/node/{nodeId}")
    public void deleteNode(@PathVariable String nodeId){
        log.info("删除点位：{}", nodeId);
        nodeService.deleteNode(nodeId);
    }
}
